
/*********************************  COPYRIGHT 2020 --------  *********  BEGIN OF FILE  ********************************/

/**********************************************************************
* @file           : at24c512c.c
* @author         : --
* @version        : --
* @date           : 2020-11-25
* @brief          : at24c512c program body
* @Description    : --
**********************************************************************/

/*-- Includes -------------------------------------------------------*/
#include "at24c512c.h"
#include "i2c1.h"

#include "cali_reagent.h"

/*-- Private typedef ------------------------------------------------*/
/*-- Private define -------------------------------------------------*/

//-----------------------------------------//
#define	AT24C512_PAGE_SIZE   128   // 128byte
#define	AT24C512_PAGE_NUM   512
#define	AT24C512_TOTAL_SIZE   65535  //B

//-----------------------------------------//
#define AT24C512_WRITE_ADDR   0xa0
#define AT24C512_READ_ADDR   0xa1



/*-- Private macro --------------------------------------------------*/
/*-- Private variables ----------------------------------------------*/

//-----------------------------------------//



/*-- Private function prototypes ------------------------------------*/

//-----------------------------------------//



/*-- Private functions ----------------------------------------------*/

/**********************************************************************
* @Fuctionname   : None
* @Brief         : None
* @Input         : None
* @Output        : None
* @Return        : None
* @Remark        : None
**********************************************************************/
void AT24C512C_Init(void)
{
	I2C1_Config();
}


/**********************************************************************
* @Fuctionname   : None
* @Brief         : None
* @Input         : None
* @Output        : None
* @Return        : None
* @Remark        : None
**********************************************************************/
s8 AT24C512_Wrtie_CaliParam(u8 * buff, u16 len)
{		
	return I2C1_Write(AT24C512_WRITE_ADDR, 0, buff, len);
}


/**********************************************************************
* @Fuctionname   : None
* @Brief         : None
* @Input         : None
* @Output        : None
* @Return        : None
* @Remark        : None
**********************************************************************/
s8 AT24C512_Read_CaliParam(u8 * buff, u16 len)
{	
	return I2C1_Read(AT24C512_READ_ADDR, 0, buff, len);	
}


/**********************************************************************
* @Fuctionname   : None
* @Brief         : None
* @Input         : None
* @Output        : None
* @Return        : None
* @Remark        : None
**********************************************************************/
s8 AT24C512_Wrtie_PwmParam(u8 * buff, u16 len)
{	
	u8 i, num;
	
	num = len / AT24C512_PAGE_SIZE;
	for (i=0; i<num; i++)
	{
		//s8 I2C1_Write(u16 DevAddress, u16 MemAddress, u8 *buff, u8 len)
		
		I2C1_Write(AT24C512_WRITE_ADDR, (i + 10) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, AT24C512_PAGE_SIZE);
	}
	
	return I2C1_Write(AT24C512_WRITE_ADDR, (i + 10) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, len % AT24C512_PAGE_SIZE);
}


/**********************************************************************
* @Fuctionname   : None
* @Brief         : None
* @Input         : None
* @Output        : None
* @Return        : None
* @Remark        : None
**********************************************************************/
s8 AT24C512_Read_PwmParam(u8 * buff, u16 len)
{	
	u8 i, num;
	
	num = len / AT24C512_PAGE_SIZE;
	for (i=0; i<num; i++)
	{
		I2C1_Read(AT24C512_READ_ADDR, (i + 10) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, AT24C512_PAGE_SIZE);
	}
	
	return I2C1_Read(AT24C512_READ_ADDR, (i + 10) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, len % AT24C512_PAGE_SIZE);
	
}



//校准板校准温度数据存储
s8  AT24C512_Wrtie_Board_Tmp_Cail_Data(u8 * buff, u16 len)
{	
	u8 i, num;
	
	num = len / AT24C512_PAGE_SIZE;
	for (i=0; i<num; i++)
	{
		//s8 I2C1_Write(u16 DevAddress, u16 MemAddress, u8 *buff, u8 len)
		
		I2C1_Write(AT24C512_WRITE_ADDR, (i + 20) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, AT24C512_PAGE_SIZE);
	}
	
	return I2C1_Write(AT24C512_WRITE_ADDR, (i + 20) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, len % AT24C512_PAGE_SIZE);
}


s8  AT24C512_Read_Board_Tmp_Cail_Data(u8 * buff, u16 len)
{	
	u8 i, num;
	
	num = len / AT24C512_PAGE_SIZE;
	for (i=0; i<num; i++)
	{
		I2C1_Read(AT24C512_READ_ADDR, (i + 20) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, AT24C512_PAGE_SIZE);
	}
	
	return I2C1_Read(AT24C512_READ_ADDR, (i + 20) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, len % AT24C512_PAGE_SIZE);
	
}


//试剂校准温度数据存储
s8  AT24C512_Wrtie_Reagent_Tmp_Cail_Data(u8 * buff, u16 len)
{	
	u8 i, num;
	
	num = len / AT24C512_PAGE_SIZE;
	for (i=0; i<num; i++)
	{
		//s8 I2C1_Write(u16 DevAddress, u16 MemAddress, u8 *buff, u8 len)
		
		I2C1_Write(AT24C512_WRITE_ADDR, (i + 80) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, AT24C512_PAGE_SIZE);
	}
	
	return I2C1_Write(AT24C512_WRITE_ADDR, (i + 80) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, len % AT24C512_PAGE_SIZE);
}


s8  AT24C512_Read_Reagent_Tmp_Cail_Data(u8 * buff, u16 len)
{	
	s8 rett=0;
	u8 i, num;
	
	num = len / AT24C512_PAGE_SIZE;
	for (i=0; i<num; i++)
	{
		I2C1_Read(AT24C512_READ_ADDR, (i + 80) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, AT24C512_PAGE_SIZE);
	}
	 rett= I2C1_Read(AT24C512_READ_ADDR, (i + 80) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, len % AT24C512_PAGE_SIZE);
	return rett;
}





//PWM校准pwm数据存储
s8  AT24C512_Wrtie_Pwm_Tmp_Cail_Data(u8 * buff, u16 len)
{	
	u8 i, num;
	
	num = len / AT24C512_PAGE_SIZE;
	for (i=0; i<num; i++)
	{
		//s8 I2C1_Write(u16 DevAddress, u16 MemAddress, u8 *buff, u8 len)
		
		I2C1_Write(AT24C512_WRITE_ADDR, (i + 140) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, AT24C512_PAGE_SIZE);
	}
	
	return I2C1_Write(AT24C512_WRITE_ADDR, (i + 140) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, len % AT24C512_PAGE_SIZE);
}


s8  AT24C512_Read_Pwm_Tmp_Cail_Data(u8 * buff, u16 len)
{	
	u8 i, num;
	
	num = len / AT24C512_PAGE_SIZE;
	for (i=0; i<num; i++)
	{
		I2C1_Read(AT24C512_READ_ADDR, (i + 140) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, AT24C512_PAGE_SIZE);
	}
	
	return I2C1_Read(AT24C512_READ_ADDR, (i + 140) * AT24C512_PAGE_SIZE, buff + i * AT24C512_PAGE_SIZE, len % AT24C512_PAGE_SIZE);
	
}











/*********************************  COPYRIGHT 2020 --------  *********  END OF FILE  **********************************/



